package com.wuyou.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * description
 * author 刘雷雨
 * date 2022/9/14 19:58
 * version 1.0
 **/
@Configuration
public class ElasticSearchClientConfig {

    @Value("${es.host}")
    private String host;

    @Value("${es.port}")
    private Integer port;

    @Value("${es.scheme}")
    private String scheme;

    //控制反转高级客户端
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        // 指定ip 端口 协议
        HttpHost httpHost = new HttpHost(host,port,scheme);
        // 创建client
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHost));
        return client;
    }
}
